/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mnstudent.presentationlayer;

import mnstudent.global.MyTableCellRender;
import mnstudent.global.DataTable;
import mnstudent.businessLayer.AcademicYearBLL;
import mnstudent.businessLayer.InfoSemesterYearBLL;
import mnstudent.businessLayer.ListSubjectOpenBLL;
import mnstudent.businessLayer.ScoresBLL;
import mnstudent.businessLayer.SemesterBLL;
import mnstudent.businessLayer.StudentBLL;
import mnstudent.datatranferobject.AcademicYearDTO;
import mnstudent.datatranferobject.ScoreStudentDTO;
import mnstudent.datatranferobject.SemesterDTO;
import mnstudent.datatranferobject.SubjectDisplay;
import java.awt.Component;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.Vector;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;

/**
 *
 * @author lee
 */
public class frmScores extends javax.swing.JPanel {

    private ListSubjectOpenBLL m_ListSubjectOpenBLL;
    private InfoSemesterYearBLL m_InfoSemesterYearBLL;
    private SemesterBLL m_SemesterBLL;
    private AcademicYearBLL m_AcademicYearBLL;
    private StudentBLL m_StudentBLL;
    private ScoresBLL m_ScoresBLL;
    private SemesterDTO objAddNewSemester;
    private AcademicYearDTO objAddNewYear;
    ArrayList<SemesterDTO> listSemesterObj;
    ArrayList<AcademicYearDTO> listYearObj;
    ArrayList<SubjectDisplay> listSubjectOpen;
    ArrayList<ScoreStudentDTO> listScoreStudent;
    private int currentRow = 0;
    //private boolean m_isSave = false;
    private DefaultTableModel m_Model, m_ModelOpenSubject;
    private final SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");

    /**
     * Creates new form frmFaculty
     */
    public frmScores() {
        initComponents();
        initControls();
        prepare();
    }

    private void initControls() {
        jxTbOpenSubjects.setEditable(false);

        if (!this.jxtabDetails.m_isAdd) {
            jxtabDetails.setEditable(false);
            jxBtnEdit.setEnabled(true);
            jxBtnSave.setEnabled(false);
            jxBtnCancel.setEnabled(false);
        } else {
            jxtabDetails.setEditable(true);
            jxBtnEdit.setEnabled(false);
            jxBtnSave.setEnabled(true);
            jxBtnCancel.setEnabled(true);
        }
    }

    private void prepare() {

        //Set lai text cac button cua dialog
        UIManager.put("OptionPane.cancelButtonText", "Hủy");
        UIManager.put("OptionPane.noButtonText", "Không");
        UIManager.put("OptionPane.okButtonText", "Có");
        UIManager.put("OptionPane.yesButtonText", "Vâng");
        //
        this.m_ListSubjectOpenBLL = new ListSubjectOpenBLL();
        this.m_InfoSemesterYearBLL = new InfoSemesterYearBLL();
        this.m_SemesterBLL = new SemesterBLL();
        this.m_AcademicYearBLL = new AcademicYearBLL();
        this.m_StudentBLL = new StudentBLL();
        this.m_ScoresBLL = new ScoresBLL();
        this.listScoreStudent = new ArrayList<>();
        bindingDataToComboBox();

        //Du len ben JTable cac mon dc mo
        m_ModelOpenSubject = (DefaultTableModel) jxTbOpenSubjects.getModel();
        String idYear = ((AcademicYearDTO) jxCbYear.getSelectedItem()).getAcademicYearID();
        String idSemester = ((SemesterDTO) jxCbSemester.getSelectedItem()).getSemesterID();
        listSubjectOpen = m_ListSubjectOpenBLL.getAllListSubjectOpenBySemesterYearToArray(idYear, idSemester);
        DataTable.addRow(m_ListSubjectOpenBLL.getAllListSubjectOpenBySemesterYear(idYear, idSemester), m_ModelOpenSubject);
        jxTbOpenSubjects.setDefaultRenderer(Object.class, new MyTableCellRender());
        jxTbOpenSubjects.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent lse) {

                if (!(jxTbOpenSubjects.getSelectionModel().isSelectionEmpty())) {
                    //retrieving the selected row index
                    currentRow = jxTbOpenSubjects.getSelectedRow();
                    //if a single row is selected from the table, take each cell values into the controls
                    if (jxTbOpenSubjects.getRowSelectionAllowed() && jxTbOpenSubjects.getRowCount() > 0) {
                        if (jxtabDetails.m_isAdd) {
                            int rs = JOptionPane.showOptionDialog(null,
                                    "Vui lòng lưu thay đổi trước khi chuyển sang dòng khác!",
                                    "Cảnh báo",
                                    JOptionPane.YES_NO_OPTION,
                                    JOptionPane.QUESTION_MESSAGE,
                                    null,
                                    null,
                                    null);
                            if (rs == 0)//Yes
                            {
                                save();
                            } else {
                                cancelAction();
                            }
                        } else {
                            String idSubject = jxTbOpenSubjects.getValueAt(currentRow, 0).toString();
                            String idYear = ((AcademicYearDTO) jxCbYear.getSelectedItem()).getAcademicYearID();
                            String idSemester = ((SemesterDTO) jxCbSemester.getSelectedItem()).getSemesterID();
                            listScoreStudent = m_StudentBLL.getAllListScoreStudentBySubjectSemesterYearToArray(idSubject, idYear, idSemester);
                            initJTableForScoreStudent(listScoreStudent);
                        }
                    }
                }
            }
        });
    }

    private void initJTableForSubjectOpen(ArrayList<SubjectDisplay> _arrSubjectOpen) {
        m_ModelOpenSubject = (DefaultTableModel) jxTbOpenSubjects.getModel();
        m_ModelOpenSubject.fireTableDataChanged();
        m_ModelOpenSubject.fireTableStructureChanged();
        if (_arrSubjectOpen.size() > 0) {
            m_ModelOpenSubject.getDataVector().removeAllElements();

            for (SubjectDisplay obj : _arrSubjectOpen) {
                Vector _row = new Vector();
                _row.addElement(obj.getSubjectID());
                _row.addElement(obj.getNameOfSubject());
                _row.addElement(obj.getNameKindOfSubject());
                _row.addElement(obj.getCoutSCredit());
                m_ModelOpenSubject.addRow(_row);
            }
        } else {
            if (m_ModelOpenSubject.getRowCount() > 0) {
                for (int i = m_ModelOpenSubject.getRowCount() - 1; i >= 0; i--) {
                    m_ModelOpenSubject.removeRow(i);
                }
            }
        }
        jxTbOpenSubjects.setDefaultRenderer(Object.class, new MyTableCellRender());
    }

    private void initJTableForScoreStudent(ArrayList<ScoreStudentDTO> _arrScoreStudent) {
        m_Model = (DefaultTableModel) jxtabDetails.getModel();
        m_Model.fireTableDataChanged();
        m_Model.fireTableStructureChanged();
        if (_arrScoreStudent.size() > 0) {
            m_Model.getDataVector().removeAllElements();

            for (ScoreStudentDTO obj : _arrScoreStudent) {
                Vector _row = new Vector();
                _row.addElement(obj.getStudentID());
                _row.addElement(obj.getFullName());
                _row.addElement(obj.getScore());
                m_Model.addRow(_row);
            }
        } else {
            if (m_Model.getRowCount() > 0) {
                for (int i = m_Model.getRowCount() - 1; i >= 0; i--) {
                    m_Model.removeRow(i);
                }
            }
        }
        jxtabDetails.setDefaultRenderer(Object.class, new MyTableCellRender());
        TableColumn col = jxtabDetails.getColumnModel().getColumn(2);
        TableCellEditor editor = jxtabDetails.getDefaultEditor(JTextField.class);

        col.setCellEditor(editor);
        editor.addCellEditorListener(new CellEditorListener() {

            @Override
            public void editingStopped(ChangeEvent e) {
                DefaultCellEditor obj = (DefaultCellEditor) e.getSource();
                Float score = Float.parseFloat(obj.getCellEditorValue().toString());
                if (jxtabDetails.getSelectedRow() != -1) {
                    if (score > 10 || score < 0) {
                        jxtabDetails.setValueAt(0, jxtabDetails.getSelectedRow(), 2);
                    } else {
                        ScoreStudentDTO sobj = listScoreStudent.get(jxtabDetails.getSelectedRow());
                        sobj.setScore(score);
                        listScoreStudent.set(jxtabDetails.getSelectedRow(), sobj);
//                        initJTableForScoreStudent(listScoreStudent);
                        System.out.println("asds");
                    }
                }
            }

            @Override
            public void editingCanceled(ChangeEvent e) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
    }

    private void bindingDataToComboBox() {
        //ComboxBox Hoc ky
        listSemesterObj = m_SemesterBLL.getAllSemesterToArray();
        objAddNewSemester = new SemesterDTO("HKThemMoi", "Thêm mới...");
        listSemesterObj.add(objAddNewSemester);
        DefaultComboBoxModel dfCbModelS = new DefaultComboBoxModel(listSemesterObj.toArray());
        jxCbSemester.setModel(dfCbModelS);

        //ComboxBox Nam Hoc
        listYearObj = m_AcademicYearBLL.getAllAcademicYearToArray();
        objAddNewYear = new AcademicYearDTO("NHThemMoi", "Thêm mới...");
        listYearObj.add(objAddNewYear);
        DefaultComboBoxModel dfCbModel = new DefaultComboBoxModel(listYearObj.toArray());
        jxCbYear.setModel(dfCbModel);
    }

    /**
     * Ham Save
     *
     * @return
     */
    private boolean isSave() {
        boolean m_isSave = false;
        for (int i = 0; i < listScoreStudent.size(); i++) {
            if (m_ScoresBLL.insertScoreStudentDetail(listScoreStudent.get(i))) {
                m_isSave = true;
            } else {
                return false;
            }
        }

        return m_isSave;
    }

    /**
     * Ham thuc hien viec cap nhat va update
     */
    private void save() {
        if (this.jxtabDetails.m_isAdd) {
            if (isSave()) {
                JOptionPane.showOptionDialog(null,
                        "Lưu xuống thành công!",
                        "Thông báo",
                        JOptionPane.YES_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        null,
                        null);
                //neu luu thanh cong
                this.jxtabDetails.m_isAdd = false;
                initControls();
                refreshDataInJTable();
            } else {
                JOptionPane.showMessageDialog(null, "Lưu xuống thất bại. Vui lòng kiểm tra lại!", "Lỗi", JOptionPane.YES_OPTION);
            }
        }
    }

    private void cancelAction() {
        if (this.jxtabDetails.m_isAdd) {
            this.jxtabDetails.m_isAdd = false;
            initControls();
        }
        refreshDataInJTable();
    }

    private void refreshDataInJTable() {
        if (!(jxTbOpenSubjects.getSelectionModel().isSelectionEmpty())) {
            //retrieving the selected row index
            currentRow = jxTbOpenSubjects.getSelectedRow();
            //if a single row is selected from the table, take each cell values into the controls
            if (jxTbOpenSubjects.getRowSelectionAllowed() && jxTbOpenSubjects.getRowCount() > 0) {
                String idSubject = jxTbOpenSubjects.getValueAt(currentRow, 0).toString();
                String idYear = ((AcademicYearDTO) jxCbYear.getSelectedItem()).getAcademicYearID();
                String idSemester = ((SemesterDTO) jxCbSemester.getSelectedItem()).getSemesterID();
                listScoreStudent = m_StudentBLL.getAllListScoreStudentBySubjectSemesterYearToArray(idSubject, idYear, idSemester);
                initJTableForScoreStudent(listScoreStudent);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jxpanDetails = new org.jdesktop.swingx.JXPanel();
        jpanTableDetails = new javax.swing.JPanel();
        jpanContent = new javax.swing.JPanel();
        jpanFuntionalDetails = new javax.swing.JPanel();
        jxBtnSave = new org.jdesktop.swingx.JXButton();
        jxBtnCancel = new org.jdesktop.swingx.JXButton();
        jxBtnEdit = new javax.swing.JButton();
        jxpanCenter = new org.jdesktop.swingx.JXPanel();
        jXPanel2 = new org.jdesktop.swingx.JXPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jxTbOpenSubjects = new mnstudent.global.MyTable();
        jxpanFindNavibar1 = new org.jdesktop.swingx.JXPanel();
        jxSearchFaculty2 = new org.jdesktop.swingx.JXSearchField();
        jXLabel3 = new org.jdesktop.swingx.JXLabel();
        jXLabel4 = new org.jdesktop.swingx.JXLabel();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jScrollPane = new javax.swing.JScrollPane();
        jxtabDetails = new mnstudent.global.MyTable();
        jxpanFindNavibar2 = new org.jdesktop.swingx.JXPanel();
        jxSearchFaculty4 = new org.jdesktop.swingx.JXSearchField();
        jXLabel6 = new org.jdesktop.swingx.JXLabel();
        jXLabel7 = new org.jdesktop.swingx.JXLabel();
        jxpanHeader = new org.jdesktop.swingx.JXPanel();
        jxpanTitleHeader = new org.jdesktop.swingx.JXPanel();
        jXLabel5 = new org.jdesktop.swingx.JXLabel();
        jxpanInfoHeader = new org.jdesktop.swingx.JXPanel();
        jxpanInfo = new org.jdesktop.swingx.JXPanel();
        jxLabNameOfFaculty = new org.jdesktop.swingx.JXLabel();
        jxCbSemester = new org.jdesktop.swingx.JXComboBox();
        jxLabNameOfFaculty2 = new org.jdesktop.swingx.JXLabel();
        jxCbYear = new org.jdesktop.swingx.JXComboBox();

        setLayout(new java.awt.BorderLayout());

        jxpanDetails.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanDetails.setLayout(new java.awt.BorderLayout());

        jpanTableDetails.setLayout(new java.awt.BorderLayout());

        jpanContent.setLayout(new java.awt.BorderLayout());

        jxBtnSave.setText("Lưu xuống");
        jxBtnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnSaveActionPerformed(evt);
            }
        });

        jxBtnCancel.setText("Hủy bỏ");
        jxBtnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnCancelActionPerformed(evt);
            }
        });

        jxBtnEdit.setText("Nhập điểm");
        jxBtnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnEditActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpanFuntionalDetailsLayout = new javax.swing.GroupLayout(jpanFuntionalDetails);
        jpanFuntionalDetails.setLayout(jpanFuntionalDetailsLayout);
        jpanFuntionalDetailsLayout.setHorizontalGroup(
            jpanFuntionalDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpanFuntionalDetailsLayout.createSequentialGroup()
                .addContainerGap(1432, Short.MAX_VALUE)
                .addComponent(jxBtnEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jxBtnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jxBtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(70, 70, 70))
        );
        jpanFuntionalDetailsLayout.setVerticalGroup(
            jpanFuntionalDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpanFuntionalDetailsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanFuntionalDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jxBtnEdit, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jxBtnSave, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jxBtnCancel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jpanContent.add(jpanFuntionalDetails, java.awt.BorderLayout.PAGE_END);

        jxpanCenter.setLayout(new java.awt.GridLayout(1, 0, 10, 0));

        jXPanel2.setLayout(new java.awt.BorderLayout(0, 1));

        jxTbOpenSubjects.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã môn học", "Tên môn học", "Loại môn học", "Số tín chỉ"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jxTbOpenSubjects.setGridColor(new java.awt.Color(153, 153, 153));
        jxTbOpenSubjects.setSelectionBackground(new java.awt.Color(204, 204, 204));
        jxTbOpenSubjects.setSortsOnUpdates(false);
        jScrollPane1.setViewportView(jxTbOpenSubjects);

        jXPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jxpanFindNavibar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanFindNavibar1.setPreferredSize(new java.awt.Dimension(914, 30));

        jXLabel3.setText("Tìm kiếm môn học:");

        jXLabel4.setText("Danh sách môn học");
        jXLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        javax.swing.GroupLayout jxpanFindNavibar1Layout = new javax.swing.GroupLayout(jxpanFindNavibar1);
        jxpanFindNavibar1.setLayout(jxpanFindNavibar1Layout);
        jxpanFindNavibar1Layout.setHorizontalGroup(
            jxpanFindNavibar1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanFindNavibar1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 465, Short.MAX_VALUE)
                .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jxSearchFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jxpanFindNavibar1Layout.setVerticalGroup(
            jxpanFindNavibar1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanFindNavibar1Layout.createSequentialGroup()
                .addGroup(jxpanFindNavibar1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxSearchFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 4, Short.MAX_VALUE))
        );

        jXPanel2.add(jxpanFindNavibar1, java.awt.BorderLayout.NORTH);

        jxpanCenter.add(jXPanel2);

        jXPanel1.setLayout(new java.awt.BorderLayout(0, 1));

        jxtabDetails.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã số sinh viên", "Tên sinh viên", "Điểm"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Float.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jxtabDetails.setGridColor(new java.awt.Color(153, 153, 153));
        jxtabDetails.setSelectionBackground(new java.awt.Color(204, 204, 204));
        jxtabDetails.setSortsOnUpdates(false);
        jScrollPane.setViewportView(jxtabDetails);

        jXPanel1.add(jScrollPane, java.awt.BorderLayout.CENTER);

        jxpanFindNavibar2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanFindNavibar2.setPreferredSize(new java.awt.Dimension(914, 30));

        jXLabel6.setText("Tìm kiếm sinh viên:");

        jXLabel7.setText("Danh sách điểm sinh viên");
        jXLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        javax.swing.GroupLayout jxpanFindNavibar2Layout = new javax.swing.GroupLayout(jxpanFindNavibar2);
        jxpanFindNavibar2.setLayout(jxpanFindNavibar2Layout);
        jxpanFindNavibar2Layout.setHorizontalGroup(
            jxpanFindNavibar2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanFindNavibar2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 429, Short.MAX_VALUE)
                .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jxSearchFaculty4, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jxpanFindNavibar2Layout.setVerticalGroup(
            jxpanFindNavibar2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanFindNavibar2Layout.createSequentialGroup()
                .addGroup(jxpanFindNavibar2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxSearchFaculty4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 4, Short.MAX_VALUE))
        );

        jXPanel1.add(jxpanFindNavibar2, java.awt.BorderLayout.NORTH);

        jxpanCenter.add(jXPanel1);

        jpanContent.add(jxpanCenter, java.awt.BorderLayout.CENTER);

        jpanTableDetails.add(jpanContent, java.awt.BorderLayout.CENTER);

        jxpanDetails.add(jpanTableDetails, java.awt.BorderLayout.CENTER);

        add(jxpanDetails, java.awt.BorderLayout.CENTER);

        jxpanHeader.setLayout(new java.awt.BorderLayout());

        jxpanTitleHeader.setBorder(new org.jdesktop.swingx.border.DropShadowBorder());

        jXLabel5.setForeground(new java.awt.Color(0, 102, 255));
        jXLabel5.setText("THÔNG TIN ĐIỂM SINH VIÊN");
        jXLabel5.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        jxpanTitleHeader.add(jXLabel5);

        jxpanHeader.add(jxpanTitleHeader, java.awt.BorderLayout.PAGE_START);

        jxpanInfoHeader.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanInfoHeader.setLayout(new java.awt.BorderLayout());

        jxpanInfo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "THÔNG TIN", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));

        jxLabNameOfFaculty.setText("Học kỳ ");

        jxCbSemester.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jxCbSemesterItemStateChanged(evt);
            }
        });

        jxLabNameOfFaculty2.setText("Năm học");

        jxCbYear.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jxCbYearItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jxpanInfoLayout = new javax.swing.GroupLayout(jxpanInfo);
        jxpanInfo.setLayout(jxpanInfoLayout);
        jxpanInfoLayout.setHorizontalGroup(
            jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanInfoLayout.createSequentialGroup()
                .addGap(136, 136, 136)
                .addComponent(jxLabNameOfFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jxCbSemester, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(230, 230, 230)
                .addComponent(jxLabNameOfFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jxCbYear, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(1098, Short.MAX_VALUE))
        );
        jxpanInfoLayout.setVerticalGroup(
            jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jxpanInfoLayout.createSequentialGroup()
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxCbSemester, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLabNameOfFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLabNameOfFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxCbYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jxpanInfoHeader.add(jxpanInfo, java.awt.BorderLayout.CENTER);

        jxpanHeader.add(jxpanInfoHeader, java.awt.BorderLayout.CENTER);

        add(jxpanHeader, java.awt.BorderLayout.NORTH);
    }// </editor-fold>//GEN-END:initComponents

    private void jxBtnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnSaveActionPerformed

        save();
    }//GEN-LAST:event_jxBtnSaveActionPerformed

    private void jxCbYearItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jxCbYearItemStateChanged
        if (jxCbYear.getSelectedItem() != null) {
            AcademicYearDTO obj = (AcademicYearDTO) evt.getItem();
            if (obj.equals(objAddNewYear)) {
                JOptionPane.showMessageDialog(null, "Thêm mới NAM HOC!");
                jxCbYear.setSelectedItem(null);
            } else {
                if (jxCbSemester.getSelectedItem() != null) {
                    String idSemester = ((SemesterDTO) jxCbSemester.getSelectedItem()).getSemesterID();
                    listSubjectOpen = m_ListSubjectOpenBLL.getAllListSubjectOpenBySemesterYearToArray(obj.getAcademicYearID(), idSemester);
                    initJTableForSubjectOpen(listSubjectOpen);
                    if (jxTbOpenSubjects.getRowCount() > 0) {
                        String idSubject = jxTbOpenSubjects.getValueAt(0, 0).toString();
                        String idYear = ((AcademicYearDTO) jxCbYear.getSelectedItem()).getAcademicYearID();
                        //String idSemester = ((SemesterDTO) jxCbSemester.getSelectedItem()).getSemesterID();
                        listScoreStudent = m_StudentBLL.getAllListScoreStudentBySubjectSemesterYearToArray(idSubject, idYear, idSemester);
                        initJTableForScoreStudent(listScoreStudent);
                    } else {
                        jxtabDetails.removeAll();
                    }
                }
            }
        }
    }//GEN-LAST:event_jxCbYearItemStateChanged

    private void jxCbSemesterItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jxCbSemesterItemStateChanged
        if (jxCbSemester.getSelectedItem() != null) {
            SemesterDTO obj = (SemesterDTO) evt.getItem();
            if (obj.equals(objAddNewSemester)) {
                JOptionPane.showMessageDialog(null, "Thêm mới HOC KY!");
                jxCbSemester.setSelectedItem(null);
            } else {
                if (jxCbYear.getSelectedItem() != null) {
                    String idYear = ((AcademicYearDTO) jxCbYear.getSelectedItem()).getAcademicYearID();
                    listSubjectOpen = m_ListSubjectOpenBLL.getAllListSubjectOpenBySemesterYearToArray(idYear, obj.getSemesterID());
                    initJTableForSubjectOpen(listSubjectOpen);
                    if (jxTbOpenSubjects.getRowCount() > 0) {
                        String idSubject = jxTbOpenSubjects.getValueAt(0, 0).toString();
                        // String idYear = ((AcademicYearDTO) jxCbYear.getSelectedItem()).getAcademicYearID();
                        String idSemester = ((SemesterDTO) jxCbSemester.getSelectedItem()).getSemesterID();
                        listScoreStudent = m_StudentBLL.getAllListScoreStudentBySubjectSemesterYearToArray(idSubject, idYear, idSemester);
                        initJTableForScoreStudent(listScoreStudent);
                    } else {
                        jxtabDetails.removeAll();
                    }
                }
            }
        }    }//GEN-LAST:event_jxCbSemesterItemStateChanged

    private void jxBtnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnEditActionPerformed
        if (jxtabDetails.getRowCount() <= 0) {
            return;
        }

        if (!this.jxtabDetails.m_isAdd) {
            this.jxtabDetails.m_isAdd = true;
            initControls();
        }
    }//GEN-LAST:event_jxBtnEditActionPerformed

    private void jxBtnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnCancelActionPerformed
        cancelAction();
    }//GEN-LAST:event_jxBtnCancelActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane;
    private javax.swing.JScrollPane jScrollPane1;
    private org.jdesktop.swingx.JXLabel jXLabel3;
    private org.jdesktop.swingx.JXLabel jXLabel4;
    private org.jdesktop.swingx.JXLabel jXLabel5;
    private org.jdesktop.swingx.JXLabel jXLabel6;
    private org.jdesktop.swingx.JXLabel jXLabel7;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXPanel jXPanel2;
    private javax.swing.JPanel jpanContent;
    private javax.swing.JPanel jpanFuntionalDetails;
    private javax.swing.JPanel jpanTableDetails;
    private org.jdesktop.swingx.JXButton jxBtnCancel;
    private javax.swing.JButton jxBtnEdit;
    private org.jdesktop.swingx.JXButton jxBtnSave;
    private org.jdesktop.swingx.JXComboBox jxCbSemester;
    private org.jdesktop.swingx.JXComboBox jxCbYear;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty2;
    private org.jdesktop.swingx.JXSearchField jxSearchFaculty2;
    private org.jdesktop.swingx.JXSearchField jxSearchFaculty4;
    private mnstudent.global.MyTable jxTbOpenSubjects;
    private org.jdesktop.swingx.JXPanel jxpanCenter;
    private org.jdesktop.swingx.JXPanel jxpanDetails;
    private org.jdesktop.swingx.JXPanel jxpanFindNavibar1;
    private org.jdesktop.swingx.JXPanel jxpanFindNavibar2;
    private org.jdesktop.swingx.JXPanel jxpanHeader;
    private org.jdesktop.swingx.JXPanel jxpanInfo;
    private org.jdesktop.swingx.JXPanel jxpanInfoHeader;
    private org.jdesktop.swingx.JXPanel jxpanTitleHeader;
    private mnstudent.global.MyTable jxtabDetails;
    // End of variables declaration//GEN-END:variables
}
